package cn.mumzone.pos.ui.fragment;

import android.view.View;
import android.widget.LinearLayout;

import butterknife.BindView;
import butterknife.OnClick;
import cn.mumzone.basic.base.BaseFragment;
import cn.mumzone.basic.util.RxBus;
import cn.mumzone.basic.util.log.Elog;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.R;
import cn.mumzone.pos.event.MemberChangeEvent;
import cn.mumzone.pos.event.MoreViewChangeEvent;
import cn.mumzone.pos.util.AppUtil;

/**
 * Created by qiuzhenhuan on 2019/7/10.
 */

public class FRA_More extends BaseFragment {

    @BindView(R.id.ll_schedule)
    LinearLayout llSchedule;

    @Override
    protected void onUserVisible() {

    }

    @Override
    protected void initEventAndData() {
        //仅有排班权限 且 门店营业范围 并非只有商品售卖的情况下 展示排班
        llSchedule.setVisibility(!AppUtil.isOnlyHasGoodsBusiness() ? View.VISIBLE : View.GONE);
    }


    @OnClick({R.id.ll_off_work, R.id.ll_schedule, R.id.ll_report, R.id.ll_repository, R.id.ll_inventory, R.id.ll_inbound, R.id.ll_outbound,
            R.id.ll_inventory_order, R.id.ll_inbound_order, R.id.ll_outbound_order})
    void onViewClicked(View view) {
        /**
         * 交班跳转通过RxBus通知首页切换Fragment
         */
        switch (view.getId()) {
            case R.id.ll_off_work:
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isHandover()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIE_OFF_WORK));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_schedule:
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isScheduling()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIE_SCHEDULE));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_report:
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isStatement()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIE_REPORT));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_repository:
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isStockQuery()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIE_REPOSITORY));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_inventory:
                // TODO: 2019/9/24 盘点
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isTakeStock()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIEW_CHECK_STOCK));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_inbound:
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isStorage()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIEW_STOCK_IN));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_outbound:
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isEnterStock()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIEW_STOCK_OUT));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_inbound_order:
                // 入库单
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isStorage()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIEW_IN_WAREHOUSE));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_outbound_order:
                // 出库单
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isEnterStock()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIEW_OUT_WAREHOUSE));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
            case R.id.ll_inventory_order:
                // 盘点单
                if (AppConstants.TEMP_USER_PERMISSION != null && AppConstants.TEMP_USER_PERMISSION.isTakeStock()) {
                    RxBus.getDefault().post(new MoreViewChangeEvent(MoreViewChangeEvent.MORE_VIEW_INVENTROY));
                } else {
                    showError("您尚未开通相应权限 ~");
                }
                break;
        }
    }

    @Override
    protected int getLayout() {
        return R.layout.fra_more;
    }
}
